﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
using Models.Common;
using Models.Device;
using Models.Task;
using Nancy.TinyIoc;
using Newtonsoft.Json;

using GatewayServerService.Device;

using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Data;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using static Models.Common.EnumDeviceState;
using Dm;
using UtilsBase;
using UtilsORM.MySqlData;
using UtilsORM.MySqlData;
using UtilsORM;
using UtilsCache;

namespace GatewayServerService.Data
{
    /// <summary>
    /// 计划任务、流程步骤执行
    /// </summary>
    public class DBIotDeviceLinkageConditionLog
    {


        static string LogSave = UtilAppsettingCache.getSetting("base:logSave");
        public async void addsync(iot_device_linkage_condition_handle handle, string remark)
        {
            try
            {
                if (LogSave == "false")
                {
                    return;
                }
                EFYihongIotContext ef = new EFYihongIotContext();

                iot_device_linkage_condition_log log = new iot_device_linkage_condition_log();
                log.l_guid = Guid.NewGuid().ToString();
                log.l_l_guid = handle.lc_l_guid;
                log.l_lc_guid = handle.lc_guid;
                log.l_add_time = DateTime.Now;
                log.l_remark = remark;
                await ef.AddAsync(log);
                ef.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

    }
}
